﻿using MediatR;
using T.Basic.API.Appliction.Command.OutsourcedUnitsCommand;
using T.Basic.Repository.BasicInterface;

namespace T.Basic.API.Appliction.CommandHandlers.OutsourcedUnitsHanders
{
    /// <summary>
    /// 删除外协单位（批删）
    /// </summary>
    public class OutsourcedUnitsDeleteAllCommandHander : IRequestHandler<OutsourcedUnitsDeleteAllCommand, int>
    {
        private readonly IOutsourcedUnitsRepository _outsourcedUnitsRepository;
        public OutsourcedUnitsDeleteAllCommandHander(IOutsourcedUnitsRepository outsourcedUnitsRepository)
        {
            _outsourcedUnitsRepository = outsourcedUnitsRepository;
        }
        public async Task<int> Handle(OutsourcedUnitsDeleteAllCommand request, CancellationToken cancellationToken)
        {
            var Outid = request.OutsourcedUnitsIds;
            foreach (var item in Outid)
            {
                var DelIds =  _outsourcedUnitsRepository.GetModelsAsync(item).Result;
                DelIds.IsDeleted = true;
               
                await _outsourcedUnitsRepository.UpdateAsync(DelIds);

            }
            return 1;
        }
    }
}
